package br.rui.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.rui.persistencia.ContaDB;

/**
 * Servlet Class
 *
 * @web.servlet              name="DessAssoc"
 *                           display-name="Name for DessAssoc"
 *                           description="Description for DessAssoc"
 * @web.servlet-mapping      url-pattern="/DessAssoc"
 * @web.servlet-init-param   name="A parameter"
 *                           value="A value"
 */
@SuppressWarnings("serial")
public class DessAssoc extends HttpServlet {

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException,
		IOException {
		
		ArrayList associados =  new ArrayList();
		ContaDB contadb = new ContaDB();
		int codRui;
		String[] temp = req.getParameterValues("radiodess");
		
		if(temp!=null){
			for (int i = 0; i < temp.length; i++) {
				codRui = Integer.parseInt(temp[i].substring(0,temp[i].indexOf("#")));
				int codFornec = Integer.parseInt(temp[i].substring(temp[i].indexOf("#")+1));
				contadb.Dessassociar(codRui,codFornec);
			}
		}
		associados = (ArrayList) contadb.Associados();
		req.setAttribute("associados",associados);
		RequestDispatcher rd = getServletContext().getRequestDispatcher("/web/jsp/Dessassoc.jsp");
		rd.forward(req,resp);			
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
	throws ServletException,
	IOException {
	doGet(req, resp);
	}
}
